---
title: YAML
description: 使用 `YAML` 对配置进行修改
---

import { Tabs, Callout } from "nextra/components";

## 覆写运行逻辑

使用 `深度合并` 对原配置进行覆写，优先级低于应用常用配置覆写

如果目标是是简单值，将直接覆盖

如果遇到嵌套的对象，函数会进一步递归合并这些嵌套的对象，可以使用 `!` 修饰以强制覆盖整个对象而不是递归合并

如：

```yaml
# 直接覆盖配置中的 dns 字段为以下内容而不进行合并
dns!:
  enable: false
```

对于数组类型，可以使用 `+` 修饰进行前置/追加操作

如：

```yaml
# 直接覆盖整个规则
rules:
  - DOMAIN,baidu.com,DIRECT
# 将规则插入到原规则前面
+rules:
  - DOMAIN,baidu.com,DIRECT
# 在原规则后面追加规则
rules+:
  - DOMAIN,baidu.com,DIRECT
```

若原本的键名就以 `+` 开头或结尾，为避免歧义请以 `<>` 包裹键名

如：

```yaml
dns:
  nameserver-policy:
    # 直接覆盖原先的+.google.cn项
    <+.google.cn>:
      - 8.8.8.8
    # 插入到前面
    +<+.google.cn>:
      - 8.8.8.8
    # 追加到后面
    <+.google.cn>+:
      - 8.8.8.8
```

## 覆写运行示例

<Tabs items={["覆写前内容", "要覆写的内容", "输出内容"]}>
<Tabs.Tab>

```yaml
mixed-port: 7890

dns:
  enable: true
  ipv6: true
  enhanced-mode: fake-ip
  fake-ip-range: 28.0.0.1/8
  nameserver: [https://dns.alidns.com/dns-query]

proxies:
  - name: ss
    type: ss
    server: 127.0.0.1
    port: 443
    password: mihomo
    cipher: none

proxy-groups:
  - name: "国内"
    type: select
    proxies:
      - DIRECT

rules:
  - GEOIP,CN,DIRECT
  - MATCH,home
```

</Tabs.Tab>
<Tabs.Tab>

```yaml
mixed-port: 7895
external-ui: ui

sniffer:
  enable: true
  override-destination: false
  sniff:
    HTTP:
      ports: [80, 8080-8880]
      override-destination: true
    TLS:
      ports: [443, 8443]
    QUIC:
      ports: [443, 8443]

tun:
  enable: true
  stack: mixed
  auto-route: true
  auto-detect-interface: true
  strict-route: false
  dns-hijack:
    - any:53

dns:
  enable: true
  listen: :1053
  ipv6: true
  enhanced-mode: fake-ip
  fake-ip-filter:
    - "*"
    - "+.lan"
    - "+.local"
    - live-push.bilivideo.com
  default-nameserver:
    - https://223.5.5.5/dns-query
  nameserver:
    - https://dns.alidns.com/dns-query
    - https://doh.pub/dns-query

+proxies:
  - name: 直连
    type: direct

rule-providers:
  cn_domain:
    type: http
    interval: 86400
    behavior: domain
    format: mrs
    url: "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/cn.mrs"

+rules:
  - RULE-SET,cn_domain,CN

proxy-groups:
  - name: CN
    type: select
    proxies:
      - DIRECT
```

</Tabs.Tab>
<Tabs.Tab>

```yaml
mixed-port: 7895
external-ui: ui

sniffer:
  enable: true
  override-destination: false
  sniff:
    HTTP:
      ports: [80, 8080-8880]
      override-destination: true
    TLS:
      ports: [443, 8443]
    QUIC:
      ports: [443, 8443]

tun:
  enable: true
  stack: mixed
  auto-route: true
  auto-detect-interface: true
  strict-route: false
  dns-hijack:
    - any:53

dns:
  enable: true
  listen: :1053
  ipv6: true
  enhanced-mode: fake-ip
  fake-ip-range: 28.0.0.1/8
  fake-ip-filter:
    - "*"
    - "+.lan"
    - "+.local"
    - live-push.bilivideo.com
  default-nameserver:
    - https://223.5.5.5/dns-query
  nameserver:
    - https://dns.alidns.com/dns-query
    - https://doh.pub/dns-query

proxies:
  - name: 直连
    type: direct
  - name: ss
    type: ss
    server: 127.0.0.1
    port: 443
    password: mihomo
    cipher: none

proxy-groups:
  - name: CN
    type: select
    proxies:
      - DIRECT

rules:
  - RULE-SET,cn_domain,CN
  - GEOIP,CN,DIRECT
  - MATCH,home

rule-providers:
  cn_domain:
    type: http
    interval: 86400
    behavior: domain
    format: mrs
    url: https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/cn.mrs
```

</Tabs.Tab>
</Tabs>
